package com.eaample.wexcle.demos.web.controller;

import com.eaample.wexcle.demos.web.service.OssService;
import com.example.wexcle.demos.web.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;
import java.io.InputStream;

@RestController
@RequestMapping("/eduoss")
public class OssContrell {

    @Autowired
    private OssService ossService;
    @ApiOperation("将导入的文件上传oss保存")
    @PostMapping("/fileoss")
    public R uploadOssFile(@RequestParam("file")MultipartFile file){
       //获取上传的文件MultipartFile
        //  返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
        return R.ok().data("url",url);
    }
//读取本地文件上传到oss(读取导出数据库的压缩包到oss)
    @ApiOperation("将导出数据库的文件上传oss以便于下载")
    @PostMapping("/localoss")
    public R localoss(@RequestParam String address) {
        String url = ossService.uploadBytes(address);
        return R.ok().data("url",url);
    }
}
